package cn.fz.qwendemo01.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("ai")
@CrossOrigin(origins = "*")
public class ChatController {
    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder builder){
        this.chatClient = builder.build();
    }

    @GetMapping("steamChat")
    public Flux<String> chatSteam(@RequestParam String input, HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        return chatClient.prompt(input)
                .stream()
                .content();
    }
}
